<template>
  <view style="width: 33%;">
    <DiGui v-for="(item, index) in children" :datas="item" :key="index" />
  </view>
</template>

<script>
  import uniSegmentedControl from "../../components/uni-segmented-control/uni-segmented-control.vue"
  import DiGui from "./components/DiGui.vue"
  export default {
    components: {
      uniSegmentedControl,
      DiGui,
    },
    data() {
      return {
        items: ['第一部门', '第二部门', '第三部门', '第四部门'],
        list: [],
        current: 0,
        styleType: 'button',
        activeColor: '#007aff',
        children: [],
        arrs: [],
        arrsItem: [],
      }
    },
    onLoad() {
      this.getData();
      this.getData2();
    },
    methods: {
      async getData() {
        let {
          data: {
            zhitui
          }
        } = await this.$myRequest({
          url: "/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.userdata&app=1",
          method: "POST",
          data: {
            openid: uni.getStorageSync('openid')
          },
        })
        // console.log('查看获取到的数据', zhitui)
        this.list = zhitui
      },

      async getData2() {
        let res = await this.$myRequest({
          url: "/index.php?i=4&c=entry&m=ewei_shopv2&do=mobile&r=member.userdata.get_tree&app=1",
          method: "POST",
          data: {
            openid: uni.getStorageSync('openid')
          },
        })
        // console.log(JSON.stringify(res))
        this.children = res.data[0].children.filter((item,index) => index == 0);
        


        // res.data[0].children.forEach(item => {
        //   let b = []
        //   b.push(item)
        //   this.arrs.push(b)

        //   if (Array.isArray(item.children) && item.children.length > 0) {
        //     this.renderTreeList2(item.children);
        //   } else {}
        //   this.children.push(this.arrs)
        //   this.arrs = []

        // })
        console.log(this.children)

      },
      renderTreeList2(children = []) {
        children.forEach(item => {
          if (item.id != -1 && item.id != 1) {
            this.arrsItem.push(item)
            if (Array.isArray(item.children) && item.children.length > 0) {
              this.renderTreeList2(item.children)
            } else {}
          }
        })
        
        this.arrs.push(this.arrsItem)
        this.arrsItem = [];
      },



      renderTreeList(list = [], rank = 0, parentId = []) {
        list.forEach(item => {
          this.treeList.push({
            id: item.id,
            name: item.name,
            parentId, // 父级id数组
            rank, // 层级
            showChild: false, //子级是否显示
            show: rank === 0 // 自身是否显示
          })
          if (Array.isArray(item.children) && item.children.length > 0) {
            let parents = [...parentId];
            parents.push(item.id);
            this.renderTreeList(item.children, rank + 1, parents);
          } else {
            this.treeList[this.treeList.length - 1].lastRank = true;
          }
        })
        console.log(this.treeList);
      },

      async registerItem(item, index) {
        console.log(item, index)
        uni.navigateTo({
          url: `./register?agentid=${item.agentid}`,
        });
      },
      onClickItem(e) {
        if (this.current !== e) {
          this.current = e
        }
      },
    }
  }
</script>

<style lang="scss">
  .uni-padding-wrap {
    width: 100%;
    box-sizing: border-box;
  }

  .uni-common-mt {
    margin: 60rpx 0;
  }

  
  

  .register {
    border: 1px solid #333;
    width: 30%;
    margin: 50rpx auto 0;
  }

  .yeji {
    width: 100%;
    font-size: 20rpx;
    flex-wrap: wrap;

    .yeji_item {
      width: 50%;
      // text-align: left;
      margin-bottom: 20rpx;
      // >view {
      //   margin-left: 60rpx;
      // }
    }
  }


  .padd {
    padding: 20rpx 0;
  }
</style>
